package GUIStudy.Project.PuzzleGame.TestProgramPart;

import java.util.Random;

public class disruptArr {
    public static void main(String[] args) {
        Random r = new Random();
        int[] testArr = new int[16];
        int[] disrupt = new int[16];
        for (int i = 0; i < disrupt.length; i++) {
            disrupt[i] = i;
        }
        for (int i = 0; i < disrupt.length; i++) {
            int exchange = r.nextInt(16 - i) + i;
//            若使用以下方法交换数组中的值，可能会导致数据丢失，原因是Random的随机值可能和当前循环的数组下标一致，导致数据变为0
//            disrupt[i] += disrupt[exchange];
//            disrupt[exchange] = disrupt[i] - disrupt[exchange];
//            disrupt[i] -= disrupt[exchange];
            int temp = disrupt[i];
            disrupt[i] = disrupt[exchange];
            disrupt[exchange] = temp;
        }
        for (int i = 0; i < 16; i++) {
            for (int j = 0; j < 16; j++){
                if(disrupt[i] == j){
                    testArr[j]++;
                }
            }
        }
        for(int i : disrupt){
            System.out.print(i + ",");
        }
        System.out.println();
        for(int i : testArr){
            System.out.print(i + ",");
        }
    }
}
